package threadDemo;

public class Test3 {
    public static void main(String[] args) {
        Ticket t = new Ticket();
        Ticket t1 = new Ticket();
        Ticket t2= new Ticket();
        Ticket t3 = new Ticket();
        t1.start();
        t2.start();
        t3.start();
        t.start();
    }

}
class Ticket extends Thread {
    static private int tic = 100;


    @Override
    public void run() {
        while (true){
            synchronized (this){
                if(tic>0){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(tic--);
                }else {
                    break;
                }
            }

        }
    }
}
